﻿using System;

namespace winS.UnityEditor.UIElement
{
    public abstract class ValueControl<T> : EditorControl, IHasValue<T>
    {
        public T value { get => _value; set => SetValue(value); }

        public event Action<T> onValueChanged;

        private T _value;

        internal ValueControl(ElementFactory elementFactory) : base(elementFactory)
        {
        }

        public virtual void SetValueWithoutNotify(T value)
        {
            _value = value;
        }

        protected void OnValueChanged(T value)
        {
            onValueChanged?.Invoke(value);
        }

        protected virtual void SetValue(T value)
        {
            _value = value;
            OnValueChanged(value);
        }
    }
}
